Round

逐元素执行四舍五入(Round to Nearest Integer)运算。

该算子对输入张量的每个元素执行就近取整, 当输入值的小数部分恰好为 0.5 时,采用“远离 0”方向取整, 其行为与 C 标准库中的 round / roundf 函数一致。

\[\text{output}_i = \operatorname{round}(\text{input}_i)\]
输入:
  • input - 输入张量的数据地址。

  • length - 输入张量的总元素数量。

  • core_mask - 核掩码。

输出:
  • output - 输出张量的数据地址,其大小与 input 相同。

支持平台:

FT78NE MT7004

备注

  • FT78NE 支持的数据类型:fp32, fp64

  • MT7004 支持的数据类型:fp16, fp32

  • 当输入为 ±∞NaN 时,输出结果遵循对应平台数学库的处理规则

共享存储版本:

void fp_round_s(float *input, float *output, int length, int core_mask)
void dp_round_s(double *input, double *output, int length, int core_mask)
void hp_round_s(half *input, half *output, int length, int core_mask)

C调用示例:

 1// FT78NE 多核示例
 2#include <stdio.h>
 3#include <round.h>
 4
 5int main(int argc, char* argv[]) {
 6    float *input  = (float *)0xA0000000;   // input 在 DDR 空间
 7    float *output = (float *)0xB0000000;   // output 在 DDR 空间
 8
 9    int length = 4096;
10    int core_mask = 0xff;
11
12    fp_round_s(input, output, length, core_mask);
13    return 0;
14}

私有存储版本:

void fp_round_p(float *input, float *output, int length)
void dp_round_p(double *input, double *output, int length)
void hp_round_p(half *input, half *output, int length)

C调用示例:

 1// MT7004 单核示例
 2#include <stdio.h>
 3#include <round.h>
 4
 5int main(int argc, char* argv[]) {
 6    half *input  = (half *)0x10000000;   // input 在 L2 空间
 7    half *output = (half *)0x10010000;   // output 在 L2 空间
 8
 9    int length = 1024;
10
11    hp_round_p(input, output, length);
12    return 0;
13}